<?php

namespace V1;
class SFroute extends \ResourceClass
{
    public $isActive = true;
    public $remark = '顺丰物流路由详情通知';

    public function __construct()
    {
    }

    /*
     * 物流通知回调
     */
    public function post($postStr)
    {
        $data = array(
            'head' => array(
                'transType' => '4500',
                'transMessageId' => '',
                'code' => "EX_CODE_OPENAPI_0200",
                'message' => '路由推送成功'
            ),
            'body' => array(
                'id' => '',
                'idError' => ''
            )
        );

        try{
            $postData = json_decode($postStr,true);
            if(isset($postData['body']['id'])){
                $id = $postData['body']['id'];
                $messageId = $postData['head']['transMessageId'];

                $data['head']['transMessageId'] = $messageId;
                $data['body']['id'] = $id;
                $data['body']['idError'] = $id;
            }else{
                throw new \Exception('数据解析错误');
            }

            $insertData = array(
                'orderId' => $postData['body']['orderId'],
                'mailNo' => $postData['body']['mailNo'],
                'acceptTime' => $postData['body']['acceptTime'],
                'acceptAddress' => $postData['body']['acceptAddress'],
                'opcode' => $postData['body']['opcode'],
                'remark' => $postData['body']['remark'],
                'insert_time' => date('Y-m-d H:i:s')
            );
            $insertOrm = new \Orm\ShippingTimeLine\ShippingTimeLineClass();
            $insertOrm->__init($insertData);
            $insertOrm->insert();
            $insert = $insertOrm['id'];
            if(!$insert){
                throw new \Exception('操作失败');
            }
        }catch (\Exception $e){
            printError(201,$e->getMessage());
        }
        return $data;
    }

}